/*
 * @Author: your Name
 * @Date: 2022-07-13 15:02:25
 * @LastEditors: your Name
 * @LastEditTime: 2022-07-13 16:11:08
 * @Description: 
 */

class YRGEventBus{
  constructor() {
    this.hanles = {
      'add': []
    }
  }
  on(eventName, eventCallback, thisArg) {
    let handlers = this.hanles[eventName] 

    if(!handlers) {
      this.hanles[eventName] = []
    }
    this.hanles[eventName].push({
      eventCallback,
      thisArg
    })

  }
  emit(eventName, ...payload) {
    const handlers = this.hanles[eventName]
    if(!handlers) return 
    handlers.forEach(handler =>{
      
    })
  }
}

const eventBus = new YRGEventBus()

eventBus.on('add', function(n1, n2){
  console.log('添加1')
}, { name: 'why'})

eventBus.emit('add', '我是参数1', '我是参数2')